<template>
  <div class="main">
    <template v-for="(item, index) in options" :key="index">
      <div
        v-if="item.children.filter(i => permissionMenu.find(perm => perm.funcCode === i.permission)).length > 0"
        class="label"
      >
        {{ item.title }}
      </div>
      <van-grid
        v-if="item.children.filter(i => permissionMenu.find(perm => perm.funcCode === i.permission)).length > 0"
        class="cards"
        :column-num="2"
      >
        <van-grid-item
          v-for="(child, childIndex) in item.children.filter(i =>
            permissionMenu.find(perm => perm.funcCode === i.permission)
          )"
          :key="childIndex"
          @click="onClick(child.path)"
        >
          <div class="card">
            <div>
              <div class="title">{{ child.title }}</div>
              <div class="subtitle">{{ child.subtitle }}</div>
            </div>
            <img class="icon" :src="child.icon" />
          </div>
        </van-grid-item>
      </van-grid>
    </template>
  </div>
</template>

<script setup>
  import getPermission from '@/http/permission'
  import icon1_1 from '@/assets/icons/icon1-1.png'
  import icon2_1 from '@/assets/icons/icon2-1.png'
  import icon2_2 from '@/assets/icons/icon2-2.png'
  import icon2_3 from '@/assets/icons/icon2-3.png'
  import icon2_4 from '@/assets/icons/icon2-4.png'
  import icon3_1 from '@/assets/icons/icon3-1.png'
  import icon3_2 from '@/assets/icons/icon3-2.png'
  import icon3_3 from '@/assets/icons/icon3-3.png'
  import icon3_4 from '@/assets/icons/icon3-4.png'
  import icon3_5 from '@/assets/icons/icon3-5.png'
  const permissionMenu = ref([])
  const options = ref([
    {
      title: '数据',
      children: [{title: '数据看板', subtitle: '一键查看', icon: icon1_1, path: '/charts', permission: 'select'}],
    },
    {
      title: '证照管理',
      children: [
        {title: '证照借用', subtitle: '点击借用', icon: icon2_1, path: '/borrowSelect', permission: 'borrowSubmit'},
        {title: '证照归还', subtitle: '点击归还', icon: icon2_2, path: '/returnSelect', permission: 'returnSubmit'},
        {title: '转移申请', subtitle: '点击申请', icon: icon2_3, path: '/transferSelect', permission: 'transferSubmit'},
        {title: '转移审核', subtitle: '点击审核', icon: icon2_4, path: '/auditSelect', permission: 'auditSubmit'},
      ],
    },
    {
      title: '记录查询',
      children: [
        {title: '备案人员', subtitle: '点击查询', icon: icon3_1, path: '/filing', permission: 'select'},
        {title: '证照列表', subtitle: '点击查询', icon: icon3_2, path: '/infos', permission: 'select'},
        {title: '借用记录', subtitle: '点击查询', icon: icon3_3, path: '/borrow', permission: 'select'},
        {title: '归还记录', subtitle: '点击查询', icon: icon3_4, path: '/return', permission: 'select'},
        {title: '转移记录', subtitle: '点击查询', icon: icon3_5, path: '/transfer', permission: 'select'},
      ],
    },
  ])
  const router = useRouter()
  const onClick = path => {
    if (path) {
      router.push({path: path})
    }
  }
  onMounted(async () => {
    if (!window.PERM) {
      await getPermission()
    }
    permissionMenu.value = window.PERM.find(item => item.menuName === '证照系统-移动端')?.menuFunction
  })
</script>

<style lang="scss" scoped>
  .main {
    position: relative;
    padding: 48px 0;
  }
  .label {
    line-height: 40px;
    font-weight: 500;
    font-size: 32px;
    margin-left: 32px;
  }
  .cards {
    padding: 32px;
    --van-border-color: none;
    :deep(.van-grid-item__content) {
      padding: 0;
    }
    .card {
      font-size: 30px;
      margin-right: 24px;
      margin-bottom: 24px;
      width: 319px;
      height: 140px;
      background: #ffffff;
      box-shadow: 0px 4px 24px 0px rgba(100, 101, 102, 0.12);
      border-radius: 16px 16px 16px 16px;
      display: flex;
      align-items: center;
      justify-content: space-evenly;
      .title {
        line-height: 40px;
        font-size: 30px;
        margin-bottom: 16px;
      }
      .subtitle {
        line-height: 36px;
        font-size: 28px;
        color: #969799;
      }
      .icon {
        width: 88px;
        height: 88px;
      }
    }
  }
</style>
